using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Collections;
namespace Hannon.FeedManager.Configuration
{
    [ConfigurationCollection(typeof(SubscriptionSettings))]
    public class SubscriptionSettingsCollection : ConfigurationElementCollection
    {
        private static ConfigurationPropertyCollection _properties;


        public SubscriptionSettingsCollection()
        {
            SubscriptionSettingsCollection._properties = new ConfigurationPropertyCollection();
        }

        public void Add(SubscriptionSettings subscription)
        {
            base.BaseAdd((ConfigurationElement)subscription);
        }
        public void Remove(SubscriptionSettings subscription)
        {
            if (subscription != null)
            {
                if (base.BaseIndexOf(subscription) >= 0)
                {
                    base.BaseRemove(subscription.Url);
                }
            }
        }
        protected override System.Configuration.ConfigurationElement CreateNewElement()
        {
            return new SubscriptionSettings();
        }

        public int IndexOf(SubscriptionSettings settings)
        {
            return base.BaseIndexOf(settings);
        }

        protected override void BaseAdd(int index, ConfigurationElement element)
        {
            if (index == -1)
            {
                base.BaseAdd(element, false);
            }
            else
            {
                base.BaseAdd(index, element);
            }
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((SubscriptionSettings)element).Url;
        }
        public new SubscriptionSettings this[string url]
        {
            get
            {
                return (SubscriptionSettings)base.BaseGet(url);
            }
        }
        public SubscriptionSettings this[int index]
        {
            get
            {
                return (SubscriptionSettings)base.BaseGet(index);
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }
        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                return SubscriptionSettingsCollection._properties;
            }
        }
       
    }
}